<?php
/**
 *
 * User: anker
 * Date: 4/22/22
 * Email: <13408046898@163.com>
 **/

use think\Response;
namespace app\admin\middleware;

class Allow
{
    public function handle($request, \Closure $next)
    {

        // 处理跨域
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Max-Age: 1800');
        header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE');
        header('Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With, access-token,token,');
        // 第一次预请求不管
        if (strtoupper($request->method()) == "OPTIONS") {
            exit;
        }
        // 处理跨域
//        后置中间件
        $response = $next($request);
        return $response;
    }

    /**
     * 中间件结束调度
     * @param \think\Response $response
     * @return void
     */
    public function end(\think\Response $response)
    {

    }
}